package com.dv.web.controller.equipment;

import com.dv.common.annotation.Log;
import com.dv.common.core.controller.BaseController;
import com.dv.common.core.domain.AjaxResult;
import com.dv.common.core.page.TableDataInfo;
import com.dv.common.enums.BusinessType;
import com.dv.common.utils.DateUtils;
import com.dv.common.utils.poi.ExcelUtil;
import com.dv.driverless.domain.EquipmentCrane;
import com.dv.driverless.service.IEquipmentCraneService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 行车信息Controller
 *
 * @author ruoyi
 * @date 2023-04-06
 */
@Api("行车信息")
@RestController
@RequestMapping("/equipment/crane")
public class EquipmentCraneController extends BaseController
{
    @Autowired
    private IEquipmentCraneService equipmentCraneService;

    /**
     * 查询行车信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:crane:list')")
    @GetMapping("/list")
    public TableDataInfo list(EquipmentCrane equipmentCrane)
    {
        startPage();
        List<EquipmentCrane> list = equipmentCraneService.selectEquipmentCraneList(equipmentCrane);
        return getDataTable(list);
    }

    /**
     * 导出行车信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:crane:export')")
    @Log(title = "行车信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EquipmentCrane equipmentCrane)
    {
        List<EquipmentCrane> list = equipmentCraneService.selectEquipmentCraneList(equipmentCrane);
        ExcelUtil<EquipmentCrane> util = new ExcelUtil<EquipmentCrane>(EquipmentCrane.class);
        util.exportExcel(response, list, "行车信息数据");
    }

    /**
     * 获取行车信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:crane:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(equipmentCraneService.selectEquipmentCraneById(id));
    }

    /**
     * 新增行车信息
     */
    @PreAuthorize("@ss.hasPermi('system:crane:add')")
    @Log(title = "行车信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EquipmentCrane equipmentCrane)
    {
        equipmentCrane.setCreateDate(DateUtils.getNowDate());
        return toAjax(equipmentCraneService.insertEquipmentCrane(equipmentCrane));
    }

    /**
     * 修改行车状态
     */
    @ApiOperation("changeStatus")
    @Log(title = "行车信息",businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody EquipmentCrane equipmentCrane){
        return toAjax(equipmentCraneService.changeEquipmentCrane(equipmentCrane));
    }

    /**
     * 修改行车信息
     */
    @PreAuthorize("@ss.hasPermi('system:crane:edit')")
    @Log(title = "行车信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EquipmentCrane equipmentCrane)
    {
        return toAjax(equipmentCraneService.updateEquipmentCrane(equipmentCrane));
    }

    /**
     * 删除行车信息
     */
    @PreAuthorize("@ss.hasPermi('system:crane:remove')")
    @Log(title = "行车信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(equipmentCraneService.deleteEquipmentCraneByIds(ids));
    }
}
